﻿using System.Reflection;

namespace Elio.Controls;
internal static class ViewExtensions
{
    public static void SendClicked(this View view)
    {
        EventInfo? eventInfo = typeof(View).GetEvent("Clicked", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
        EventHandler eventHandler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), view, "OnClicked");
        eventInfo?.AddEventHandler(view, eventHandler);
        eventHandler(view, EventArgs.Empty);
        eventInfo?.RemoveEventHandler(view, eventHandler);
    }

    public static void SendFocused(this View view)
    {
        EventInfo? eventInfo = typeof(View).GetEvent("Focused", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
        EventHandler eventHandler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), view, "OnFocused");
        eventInfo?.AddEventHandler(view, eventHandler);
        eventHandler(view, EventArgs.Empty);
        eventInfo?.RemoveEventHandler(view, eventHandler);
    }
}
